using System.Collections.Generic;
using CYZHAPI.Common;
using CYZHAPI.Entity;
using CYZHAPI.IRepository.IService;
using CYZHAPI.web.Model;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace CYZHAPI.web.Controllers
{
    public class cantonController : BaseController
    {
        private ICantonService _CantonService;
        public cantonController(ICantonService cantonService, ILogger<BaseController> logger) : base(logger)
        {
            _CantonService = cantonService;
        }

        [HttpGet]
        public CantonRenBean Get(){
            CantonRenBean renBean = new CantonRenBean(){
                code = "901",
                message = "行政区数据查询失败",
                reList = null
            };
            return renBean;
        }

        [HttpGet("{id}")]
        public CantonRenBean Get(string id){
            id = id == null ? "" : id;
            CantonRenBean renBean = new CantonRenBean();
            if(id.Equals("")){
                renBean.code = "901";
                renBean.message = "行政区数据查询失败";
                renBean.reList = null;
                return renBean;
            }
            string sWhere = "name like '%"+id+"%'";
             List<CantonModel> ListInfo = _CantonService.GetList(sWhere);
            
            if(ListInfo != null){
                renBean.code = "200";
                renBean.message = "行政区数据查询成功";
                renBean.reList = ListInfo;
            }else{
                renBean.code = "901";
                renBean.message = "行政区数据查询失败";
                renBean.reList = null;
            }

            return renBean;
        }

        [Route("Seach")]
        [HttpPost]
        public CantonRenBean Seach([FromBody]CantonModel value)
        {
            return null;
        }
    }
}